﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using System.Linq;
using projectManagementWeb.Validations;
using projectManagementWeb.Controllers;
using projectManagementWeb.Models.Admin;

namespace projectManagementWeb.Models
{

    public class ChangePasswordModel
    {
        [DataType(DataType.Text)]
        [Display(Name = "Current User")]
        public string UserName { get;  set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Current password")]
        public string OldPassword { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "New password")]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm new password")]
        [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }

        
    }

    public class LogOnModel
    {
        [Required(ErrorMessage = "Se requiere un nombre de usuario válido")]
        [Display(Name = "Usuario")]
        public string UserName { get; set; }

        [Required(ErrorMessage = "Se requiere una contraseña válida. ")]
        [DataType(DataType.Password)]
        [Display(Name = "Contraseña")]
        public string Password { get; set; }

        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
    }

        public class RegisterModel
        {
            public RegisterModel()
            {

            }

            
            public RegisterModel(string userName)
            {
                MembershipUser userLocal = Membership.GetUser(userName);

                AccountController controlLayerLocal = new AccountController();
                UserDataModel userDataLocal = controlLayerLocal.GetUserData(userName);

                Email = userLocal.Email;
                FirstName = userDataLocal.FirstName;
                LastName = userDataLocal.LastName;
                OldPassword = userDataLocal.Password;
                Password = userDataLocal.Password;
                Question = userDataLocal.Question;
                Answer = userDataLocal.Answer;
                string[] tmpRoles = Roles.GetRolesForUser(userName);
                if (tmpRoles.Count() > 0)
                {
                Rol = tmpRoles[0].ToString();
                oldRol = tmpRoles[0].ToString();
                }

            }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [UserNameValidation]
            [Display(Name = "Usuario")]
            public string UserName { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [StringLength(100, ErrorMessage = "El {0} debe ser almenos de {2} caracteres de longitud.", MinimumLength = 1)]
            [Display(Name = "Nombre(s)")]
            public string FirstName { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [StringLength(100, ErrorMessage = "El {0} debe ser almenos de {2} caracteres de longitud.", MinimumLength = 1)]
            [Display(Name = "Apellido")]
            public string LastName { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [DataType(DataType.EmailAddress)]
            [Display(Name = "Correo Electrónico")]
            public string Email { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [StringLength(100, ErrorMessage = "El {0} debe ser almenos de {2} caracteres de longitud.", MinimumLength = 4)]
            [DataType(DataType.Password)]
            [Display(Name = "Contraseña")]
            public string Password { get; set; }

            [DataType(DataType.Password)]
            [Display(Name = "Confirmación de Contraseña")]
            [Compare("Password", ErrorMessage = "La Contraseña y la confirmación no coinciden.")]
            public string ConfirmPassword { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [QuestionValidation]
            [Display(Name = "Pregunta Secreta")]
            public string Question { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [Display(Name = "Respuesta Secreta")]
            public string Answer { get; set; }

            [Required(ErrorMessage = "El campo '{0}' es requerido")]
            [UserValidation]
            [Display(Name = "Rol")]
            public string Rol { get; set; }

            public string OldPassword { get; set; }
            public string oldRol { get; set; }


            public IEnumerable<SelectListItem> SecurityRoles
            {
                get
                {
                    string SecurityRoles = string.Empty;
                    string[] RolesList = Roles.GetAllRoles();

                    List<SelectListItem> items = new List<SelectListItem>();

                    items.Add(new SelectListItem() { Text = "-----------", Value = "-1", Selected = true });

                    foreach (string Description in RolesList)
                    {
                        items.Add(new SelectListItem() { Text = Description, Value = Description, Selected = false });
                    }

                    return items;
                }
            }

    }

    public class ForgotPasswordModel
    {
        [Required]
        [Display(Name = "Nombre de Usuario")]
        public string UserName { get; set; }

        [Required]
        [Display(Name = "Pregunta Secreta")]
        public string Question { get; set; }

        [Required]
        [Display(Name = "Respuesta Secreta")]
        public string Answer { get; set; }
    }

}
